package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.pojo.BannerDataEntity;
import com.egg.ylt.pojo.HomePageEntity;
import com.egg.ylt.pojo.MessageRecommendEntity;
import com.egg.ylt.presenter.IFindPresenter;
import com.egg.ylt.view.IFindView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by qiuzhenhuan on 2019/1/17.
 */

public class FindPresenterImpl extends BasePresenter<IFindView> implements IFindPresenter {

    @Override
    public void getBanner() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("companyId", Constants.COMPANYID);
        hashMap.put("token", Constants.TOKEN);
        hashMap.put("type", "f");//s 首页 f 发现
        RequestManager.getInstance().requestGetByAsyn(API.GET_BANNER_DATA, hashMap, new ReqCallBack<BannerDataEntity>() {

            @Override
            public void onReqSuccess(BannerDataEntity result) {
                mView.showBanner(result);
            }

            @Override
            public void onFailure(String result) {
//                mView.showError(result);
                mView.showException(result);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.showException(error.getMsg());
//                mView.showException(error.toString());
            }
        });
    }

    @Override
    public void getMessageRecommendPage() {

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("companyId", Constants.COMPANYID);
        RequestManager.getInstance().requestPostByAsyn(API.MESSAGE_RECOMMEND_PAGE, hashMap, new ReqCallBack<MessageRecommendEntity>() {

            @Override
            public void onReqSuccess(MessageRecommendEntity result) {
                mView.showMessageRecommend(result);
            }

            @Override
            public void onFailure(String result) {
                mView.showException(result);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.showException(error.getMsg());
            }
        });
    }
}
